{extend name='base' /}
{block name='content'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">规则管理</a>
        <a>
          <cite>规则列表</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">

  <xblock>
    <button class="layui-btn" onclick="x_admin_show('添加规则','{:url('role/nodeadd')}')"><i class="layui-icon"></i>添加
    </button>
  </xblock>
  <table class="layui-table">
    <thead>
    <tr>

      <th>ID</th>
      <th>权限规则</th>
      <th>权限名称</th>
      <th>图标</th>
      <th>类型</th>
      <th>描述</th>
      <th>状态</th>
      <th>验证状态</th>
      <th>操作</th>
    </thead>
    <tbody>
    {volist name='nodeData' id='vo'}
    <tr>

      <td>{$vo.node_id}</td>
      <td>{$vo.node_name}</td>
      <td>{$vo._name}</td>
      <td> <i class="iconfont">{$vo.icon}</i></td>
      <td>
        {switch name="$vo.type"}
        {case value="1"}<span class="layui-btn layui-btn-normal layui-btn-xs">导航</span>{/case}
        {case value="2"}<span class="layui-btn layui-btn-info layui-btn-xs">菜单</span>{/case}
        {case value="3"}<span class="layui-btn layui-btn-primary layui-btn-xs">方法</span>{/case}
        {default /}default
        {/switch}
      </td>
      <td>{$vo.describe}</td>
      <td class="td-status">
        {if $vo.status==1}
        <span class="layui-btn layui-btn-normal layui-btn-xs">已启用</span>
        {else /}
        <span class="layui-btn layui-btn-danger layui-btn-xs">已禁用</span>
        {/if}
      </td>
      <td class="td-status">
        {if $vo.is_auth==1}
        <span class="layui-btn layui-btn-normal layui-btn-xs">开启验证</span>
        {else /}
        <span class="layui-btn layui-btn-info layui-btn-xs">无需验证</span>
        {/if}
      </td>
      <td class="td-manage">
        <div class="layui-btn-group">
          <a onclick="member_stop(this,{$vo.node_id})" href="javascript:;" class="layui-btn layui-btn-warm layui-btn-xs" stu="{$vo.status}">
            {if $vo.status==1}
            停用
            {else /}
            启用
            {/if}
          </a>
          <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs"
             onclick=" x_admin_show('规则编辑','{:url('role/editnode','id='.$vo['node_id'])}')">编辑</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="member_del(this,{$vo.node_id})"
             href="javascript:;">删除</a>
          <a class="layui-btn layui-btn-info layui-btn-xs" onclick="x_admin_show('编辑','{:url('role/nodeadd','pid='.$vo['node_id'])}');"
             href="javascript:;">添加子节点</a>
        </div>
      </td>
    </tr>
    {/volist}
    </tbody>
  </table>


</div>
<script>


    /*用户-停用*/
    function member_stop(obj,id){
            var sta = $(obj).attr('stu');
            if (sta==1){
                var str ='确认要停用当前节点和所有的子节点吗？'
            } else{
                var str ='确认要启用当前节点和对应的父节点吗？'
            }
            layer.confirm(str, function (index) {
                $.ajax({
                    url:"{:url('role/upnodesta')}",
                    type:'post',
                    dataType:'json',
                    data:{id:id,sta:sta},
                    success:function (res) {
                        if (res.code) {
                            layer.msg(res.message, {icon: 6, time: 1000});
                            setTimeout(function () {
                                window.location.reload();
                            },1000)

                        } else {
                            layer.msg(res.message, {icon: 2, time: 1000})
                        }
                    },
                    error:function () {
                        layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                    }
                })


            });
    }

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？', function (index) {
            // //发异步删除数据
            $.ajax({
                url: "{:url('role/nodedel')}",
                data: {id: id},
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code) {
                        $(obj).parents("tr").remove();
                        layer.msg(res.message, {icon: 6, time: 1000});
                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error: function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })

        });
    }




</script>

</body>
{/block}